﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace Ingebet.Utils
{
    public static class DataConnection
    {
        public static SqlConnection CreateConnection()
        {
            if (ConfigurationManager.ConnectionStrings["Connexion"] == null)
            {
                throw new Exception("ConnectionString non definie dans le fichier Web.config");
            }
            var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Connexion"].ConnectionString);
            try
            {
                sqlConnection.Open();
            }
            catch (Exception exception)
            {
                throw new Exception("Erreur lors de la connexion à la base de donnée", exception);
            }
            return sqlConnection;
        }
    }
}